package com.bianxianmao.lastknow.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bianxianmao.R;
import com.bianxianmao.lastknow.bean.LastKnowBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/8/9.
 */

public class ListViewAdapter extends BaseAdapter {
    private Context mContext;
    private List<LastKnowBean.ReturnValueBean> data = new ArrayList<>();
    private LayoutInflater inflater;
    private static final int COUNTED = 1;
    private static final int COUNTING = 2;
    private static final int COUNTDOWN = 3;
    private TextView winNumber;
    private TextView winMemberBuyCount;
    private TextView winMemberName;
    private TextView periodsNumber;
    private TextView counting;
    private TextView dbOpenTime;

    public ListViewAdapter(Context mContext, List<LastKnowBean.ReturnValueBean> data) {
        this.mContext = mContext;
        this.data = data;
        this.inflater = LayoutInflater.from(mContext);
    }


    @Override
    public int getCount() {
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getViewTypeCount() {
        return 3;
    }

    @Override
    public int getItemViewType(int position) {

        return getItemViewType(position);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        int p = position;
        int type = getItemViewType(position);
        CountedViewHolder countedViewHolder = null;
        CountingViewHolder countingViewHolder = null;
        CountdownViewHolder countdownViewHolder = null;
        // 设置视图
        if (convertView == null) {
            countingViewHolder = new CountingViewHolder();
            countedViewHolder = new CountedViewHolder();
            countdownViewHolder = new CountdownViewHolder();
            switch (data.get(position).getState()) {
                case "1"://倒计时
                    convertView = inflater.inflate(R.layout.lastknow_item3, null);
                    periodsNumber = (TextView) convertView.findViewById(R.id.periodsNumber);
                    counting = (TextView) convertView.findViewById(R.id.counting);
                    countdownViewHolder.periodsNumber.setText(data.get(position).getPeriodsNumber());
                    countdownViewHolder.counting.setText(data.get(position).getDbOpenTime());
                    String trim = data.get(position).getDbOpenTime().trim();
                    convertView.setTag(countdownViewHolder);
                    break;
                case "2"://揭晓中
                    convertView = inflater.inflate(R.layout.lastknow_item2, null);
                    periodsNumber = (TextView) convertView.findViewById(R.id.periodsNumber);
                    countingViewHolder.periodsNumber.setText(data.get(position).getPeriodsNumber());
                    convertView.setTag(countingViewHolder);
                    break;
                case "3"://已经揭晓
                    convertView = inflater.inflate(R.layout.lastknow_item1, null);
                    periodsNumber = (TextView) convertView.findViewById(R.id.periodsNumber);
                    winMemberName = (TextView) convertView.findViewById(R.id.winMemberName);
                    winMemberBuyCount = (TextView) convertView.findViewById(R.id.winMemberBuyCount);
                    winNumber = (TextView) convertView.findViewById(R.id.winNumber);
                    dbOpenTime = (TextView) convertView.findViewById(R.id.dbOpenTime);

                    countedViewHolder.periodsNumber.setText(data.get(position).getPeriodsNumber());
//                countedViewHolder.winMemberName.setText(data.get(position).getwinMemberName());
//                countedViewHolder.winNumber.setText(data.get(position).getwinNumber);
                    countedViewHolder.dbOpenTime.setText(data.get(position).getDbOpenTime());
                    convertView.setTag(countedViewHolder);
                    break;
                default:
                    break;
            }
        }

        return convertView;
    }

    class CountedViewHolder {
        private TextView periodsNumber;
        private TextView winMemberName;
        private TextView winMemberBuyCount;
        private TextView winNumber;
        private TextView dbOpenTime;


    }

    class CountingViewHolder {

        private TextView periodsNumber;

    }

    class CountdownViewHolder {

        private TextView periodsNumber;
        private TextView counting;

    }
}
